<template>
  <PageListContainer>
    <BreadCrumb>
      <template #default>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>考古加代理管理</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ name: 'AgencyKgjAgentAgentList' }">代理列表</el-breadcrumb-item>
          <el-breadcrumb-item>代理兑换列表</el-breadcrumb-item>
        </el-breadcrumb>
      </template>
    </BreadCrumb>
    <div class="base-block">
      <k-search :model="state.params" @search="methods.onSearch" @reset="methods.onReset">
        <el-tabs v-model="state.params._tabActiveKey" @tab-click="onClickTab">
          <el-tab-pane
            v-for="item in tabsOptions"
            :key="item.value"
            :name="item.value"
            :label="item.label"
          ></el-tab-pane>
        </el-tabs>
        <el-form-item label="兑换码搜索" label-width="100px">
          <el-input v-model="state.params.gen_code" clearable placeholder="请输入兑换码" />
        </el-form-item>
        <el-form-item label="兑换码来源" label-width="90px">
          <el-select v-model="state.params.code_type" placeholder="不限">
            <el-option
              v-for="item in codeTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="会员类型">
          <el-select v-model="state.params.product" placeholder="不限">
            <el-option
              v-for="item in memberTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="使用状态">
          <el-select v-model="state.params.code_status" placeholder="不限">
            <el-option
              v-for="item in codeStatusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" label-width="100px">
          <el-date-picker
            v-model="state.params._dateRange"
            type="daterange"
            format="YYYY-MM-DD"
            value-format="YYYYMMDD"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :shortcuts="dateShortcut"
            @change="methods.onSearch"
          />
        </el-form-item>
      </k-search>
    </div>
    <div class="base-block">
      <KTable v-bind="tableState" v-on="tableEvent"></KTable>
    </div>
  </PageListContainer>
</template>

<script setup lang="ts">
import { useTableList, tabsOptions, codeTypeOptions, memberTypeOptions, codeStatusOptions, unsoldColumns, columns } from './hooks/use-table';
import type { TabsPaneContext } from 'element-plus';
import { useRoute } from 'vue-router';
import BreadCrumb from '@/components/base-bread-crumb/index.vue';
import { toolGetDateRangeShorcuts as dateShortcut } from '@/utils';
defineOptions({ name: 'AgencyKgjAgentExchangeCodeList' });
const route = useRoute();
const props = route.query;
const { state, tableState, tableEvent, ...methods } = useTableList({
  getParams: (params: Record<string, any>) => {
    return {
      ...params,
      colonel_id: props.id
    };
  }
});

// tab切换
const onClickTab = (tab: TabsPaneContext) => {
  state.params._tabActiveKey = tab?.paneName;
  state.columns = state.params._tabActiveKey === 0 ? unsoldColumns : columns;
  methods.onSearch();
};
</script>
